package com.geniusk.common.core;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.geniusk.common.enums.ResponseType;

/**
 * 自定义响应数据结构
 * 本类可提供给 H5/ios/安卓/公众号/小程序 使用
 * 前端接受此类数据（json object)后，可自行根据业务去实现相关功能
 */
/**
 * 自定义响应数据结构
 * 本类可提供给 H5/ios/安卓/公众号/小程序 使用
 * 前端接受此类数据（json object)后，可自行根据业务去实现相关功能
 */
public class JSONResult {

    // 响应业务状态
    private Integer code;

    // 响应消息
    private String msg;

    // 响应数据
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Object data;

    // 响应令牌
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String token;

    public static JSONResult build(Integer code, String msg, Object data) {
        return new JSONResult(code, msg, data);
    }

    public static JSONResult ok(Object data) {
        return new JSONResult(data);
    }

    public static JSONResult loginSucceed(String token) {
        return new JSONResult(token);
    }

    public static JSONResult ok() {
        return new JSONResult(ResponseType.SUCCESS);
    }

    public static JSONResult errorMsg(String msg) {
        return new JSONResult(ResponseType.FAILED, msg);
    }

    public static JSONResult errorCustom(ResponseType responseType) {
        return new JSONResult(responseType);
    }

    public JSONResult(ResponseType responseType) {
        this.code = responseType.code();
        this.msg = responseType.msg();
    }

    public JSONResult() {

    }

    public JSONResult(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public JSONResult(ResponseType responseType, String msg) {
        this.code = responseType.code();
        this.msg = msg;
    }

    public JSONResult(Object data) {
        this.code = ResponseType.SUCCESS.code();
        this.msg = ResponseType.SUCCESS.msg();
        this.data = data;
    }

    public JSONResult(String token) {
        this.code = ResponseType.SUCCESS.code();
        this.msg = ResponseType.SUCCESS.msg();
        this.token = token;
    }

    public void setToken(String token){
        this.token = token;
    }

    public String getToken(){
        return token;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

}